package com.hdaccp.news.service.impl;

import com.hdaccp.news.service.NewsService;
import com.hdaccp.pojo.po.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;
@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private EntityManager entityManager ;

    @Override
    public List<News> queryPage(int currentPage, int pageSize) {
        String jpql = "select n from News n" ;
        Query query = entityManager.createQuery(jpql) ;
        query.setFirstResult((currentPage-1) * pageSize) ;
        query.setMaxResults(pageSize) ;
        return query.getResultList();
    }
}
